//
//  ZCOrderChoiseCouponCell.m
//  ZCJZ
//
//  Created by sujeking on 2019/4/23.
//  Copyright © 2019 jeking. All rights reserved.
//

#import "ZCOrderChoiseCouponCell.h"
#import "TBCityIconFont.h"
@interface ZCOrderChoiseCouponCell()

@property (weak, nonatomic) IBOutlet UILabel *moneyLabel;
@property (weak, nonatomic) IBOutlet UILabel *nameLabel;
@property (weak, nonatomic) IBOutlet UILabel *desLabel;
@property (weak, nonatomic) IBOutlet UILabel *dateLabel;
@property (weak, nonatomic) IBOutlet UILabel *limitLabel;
@property (weak, nonatomic) IBOutlet UIButton *checkbtn;

@property (nonatomic, strong) NSDateFormatter *df;

@end

@implementation ZCOrderChoiseCouponCell

- (void)awakeFromNib {
    [super awakeFromNib];
    self.checkbtn.userInteractionEnabled = NO;
    self.checkbtn.backgroundColor = [UIColor whiteColor];
    self.selectionStyle = UITableViewCellSelectionStyleNone;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    UIImage *nimg = [UIImage iconWithInfo:TBCityIconInfoMake(@"\U0000e647", 22, [generalToolBox getColorWithHexadecimalColorStr:@"0x666666"])];
    UIImage *simg = [UIImage iconWithInfo:TBCityIconInfoMake(@"\U0000e648", 22, [generalToolBox getColorWithHexadecimalColorStr:@"0xC20114"])];
    if (selected) {
        [self.checkbtn setImage:simg forState:UIControlStateNormal];
    } else {
        [self.checkbtn setImage:nimg forState:UIControlStateNormal];
    }
}

- (void)setDict:(NSDictionary *)dict {
    _dict = dict;
    
    NSDate *start_at = [NSDate dateWithTimeIntervalSince1970:
                    [[self.dict valueForKey:@"start_at"] integerValue]];

    NSDate *end_at = [NSDate dateWithTimeIntervalSince1970:
                        [[self.dict valueForKey:@"end_at"] integerValue]];

    self.nameLabel.text = [dict valueForKey:@"name"];
    self.desLabel.text = [dict valueForKey:@"description"];
    self.dateLabel.text = [NSString stringWithFormat:@"%@-%@",[self.df stringFromDate:start_at],[self.df stringFromDate:end_at]];
    self.limitLabel.text = [NSString stringWithFormat:@"满%zd使用",
                            [[dict valueForKey:@"max"] integerValue]];
    NSString *money = [NSString stringWithFormat:@"￥%@",[dict valueForKey:@"money"]];
    NSMutableAttributedString *mstr = [[NSMutableAttributedString alloc] initWithString:money attributes:@{NSForegroundColorAttributeName:[generalToolBox getColorWithHexadecimalColorStr:@"0xC20114"]}];
    [mstr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:15] range:(NSRange){0,1}];
    [mstr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:30]
                 range:(NSRange){1,money.length - 1}];
    
    self.moneyLabel.attributedText = mstr;
}

- (NSDateFormatter *)df {
    if (_df == nil) {
        _df = [[NSDateFormatter alloc] init];
        _df.dateFormat = @"yyyy.MM.dd";
    }
    return _df;
}

@end
